// @ts-ignore
import { request } from '@umijs/max';

// 扩写
export async function express(body: API.User[], options?: { [key: string]: any }) {
  return request<{
    data: any;
  }>('/api/writings/extend', {
    method: 'POST',
    data: body,
    ...(options || {}),
  });
}

// 扩写
export async function short(body: API.User[], options?: { [key: string]: any }) {
  return request<{
    data: API.CurrentUser;
  }>('/api/writings/short', {
    method: 'POST',
    data: body,
    ...(options || {}),
  });
}

// search /api/knowledge_bases/articles/search
// /api/writings/search
export async function search(
  params?: {
    content?: string;
  },
  options?: { [key: string]: any },
) {
  console.log('params====', params);
  return request<{
    data: API.CurrentUser;
  }>('/api/knowledge_bases/articles/search', {
    method: 'GET',
    params,
    // params: { ...params },
    ...(options || {}),
  });
}

// 段落
export async function paragraphService(body: API.User[], options?: { [key: string]: any }) {
  return request<{
    data: API.CurrentUser;
  }>('/api/writings/paragraph', {
    method: 'POST',
    data: body,
    ...(options || {}),
  });
}

/** 获取当前的用户 GET /api/currentUser */
export async function currentUser(params: any, options?: { [key: string]: any }) {
  return request<{
    data: API.CurrentUser;
  }>('/api/currentUser', {
    method: 'GET',
    ...(options || {}),
  });
}
// 获取历史记录
export async function getDocuments(params: any) {
  return request<API.ReqResult>(`/api/documents`, {
    method: 'get',
    params,
  });
}
// 删除文档
export async function delDocuments(id: any) {
  return request<API.ReqResult>(`/api/documents/${id}`, {
    method: 'DELETE',
  });
}
// 文档详情
export async function getDocumentsDetail(param: any) {
  const params = param.version_no ? { version_no: param.version_no } : {};
  return request<API.ReqResult>(`/api/documents/${param.id}`, {
    method: 'GET',
    params,
  });
}
// 更新/保存文档
export async function saveDocument(body: any) {
  return request<API.ReqResult>(`/api/documents/${body.uuid}`, {
    method: 'POST',
    data: body,
  });
}
